Repository navigation
fix(npm): use case-insensitive match for trust-policy-exclude - #35520
Merged
bartlomieju merged 5 commits intoJun 29, 2026
Merged
bartlomieju merged 5 commits into
bartlomieju merged 5 commits into
Conversation
npm package names are case-insensitive by specification, but the `trust-policy-exclude[]` check was using `BTreeSet::contains`, which is a byte-exact comparison. This meant that a user writing `trust-policy-exclude[]=@MyScope/MyPkg` in `.npmrc` would not match the registry-normalised name `@myscope/mypkg`, leaving the `no-downgrade` trust policy enforced for a package the user explicitly intended to exempt. Fix: replace `BTreeSet::contains` with an `Iterator::any` using `eq_ignore_ascii_case`, which matches npm's case-insensitive package name semantics. Added four regression tests covering: - simple uppercase name in exclude (`TEST` vs registry `test`) - mixed-case exclude (`Test` vs `test`) - scoped package with mixed-case scope (`@MyScope/MyPkg` vs `@myscope/mypkg`) - reversed direction (lowercase exclude vs mixed-case registry name)
Deno Individual Contributor License AgreementAll contributors have signed the CLA. Thank you! This is an automated message from CLA Assistant |
Contributor
Author
bartlomieju
reviewed
Jun 27, 2026
bartlomieju
left a comment
Member
There was a problem hiding this comment.
Thanks for the fix and the thorough write-up — the bug is real and your analysis is spot on: npm package names are case-insensitive, so the byte-exact BTreeSet::contains was wrong. The regression tests covering both directions (mixed-case exclude vs. mixed-case registry name) are a nice touch.
The fix is correct as-is. Two non-blocking design notes to consider for an even cleaner version — see the inline comment. Neither blocks merge; both are about where normalization lives. Waiting on CI before this can land.
Per bartlomieju's review suggestion: instead of a per-call linear scan with eq_ignore_ascii_case(), lowercase the exclude entries once when the BTreeSet is built. The lookup then becomes a plain BTreeSet::contains() with O(log n) rather than O(n). Changes: - factory.rs: .iter().cloned() → .iter().map(|s| s.to_ascii_lowercase()) - common.rs: .iter().any(|e| e.eq_ignore_ascii_case(...)) → .contains(&info.name.to_ascii_lowercase()) - test helper: also normalizes to lowercase at construction to match All 7 trust_policy tests pass.
Contributor
Author
|
Thanks for the design notes! Adopted Suggestion 1 in 86e4197:
|
bartlomieju
enabled auto-merge (squash)
June 29, 2026 09:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
trust-policy-exclude[]in.npmrcuses aBTreeSet<String>::containscheck, which is a byte-exact comparison. However, npm package names are case-insensitive by specification.This means a user writing:
in their
.npmrcwould not match the registry-normalised name@myscope/mypkg, so theno-downgradetrust policy remains enforced for a package they explicitly intended to exempt.Affected code:
libs/npm/resolution/common.rs—NpmVersionResolver::get_for_package()Tests
Four regression tests added to
libs/npm/resolution/common.rs:.npmrcTESTtestTesttest@MyScope/MyPkg@myscope/mypkgmypkgMyPkgtesttestAll 6
test_trust_policy_exclude*tests pass after the fix.AI Disclosure
I used Claude (Anthropic) to assist with identifying the bug and writing the regression tests. The analysis was: reviewing the
trust-policy-excludeimplementation in#34927, noticingBTreeSet::containsis byte-exact while npm names are case-insensitive, and verifying the failure with 4 concrete test cases before applying the one-line fix.